﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace JScriptSuite.QA.Lib.System
{
    class CharTests
    {
        internal static JResultItem AllTests()
        {
            return JResultItem.CreateInstance("CharTests")
                .Push(ConstantTests(), 
                    IsDigitTests(),
                    IsWhiteSpaceTests(),
                    IsLowerTests(),
                    IsUpperTests(),
                    ToLowerTests(),
                    ToUpperTests(),
                    EqualsTests(),
                    CompareToTests());
        }


        static JResultItem ConstantTests()
        {
            return JResultItem.CreateInstance("ConstantTests")
                .Push('a', '0', '\x0', "abc"[1]);
        }

        static JResultItem IsDigitTests()
        {
            return JResultItem.CreateInstance("IsDigitTests")
                .Push(Char.IsDigit('0'), Char.IsDigit('5'), Char.IsDigit('9'), Char.IsDigit('a'), Char.IsDigit('!'));
        }

        static JResultItem IsWhiteSpaceTests()
        {
            return JResultItem.CreateInstance("IsWhiteSpaceTests")
                .Push(Char.IsWhiteSpace('0'), 
                    Char.IsWhiteSpace('a'), 
                    Char.IsWhiteSpace(' '), 
                    Char.IsWhiteSpace('\t'), 
                    Char.IsDigit('\r'),
                    Char.IsDigit('\n'),
                    Char.IsDigit('\xa0'));
        }

        static JResultItem IsLowerTests()
        {
            return JResultItem.CreateInstance("IsLowerTests")
                .Push(Char.IsLower('0'),
                    Char.IsLower('!'),
                    Char.IsLower(' '),
                    Char.IsLower('a'),
                    Char.IsLower('z'),
                    Char.IsLower('m'),
                    Char.IsLower('A'),
                    Char.IsLower('N'),
                    Char.IsLower('Z'),
                    Char.IsLower('ä'),  // german a - umlaut (lower case)
                    Char.IsLower('Ä'),   // german a - umlaut (upper case)
                    Char.IsLower("aAb", 1),
                    Char.IsLower("aAb", 2)
             );  

        }

        static JResultItem IsUpperTests()
        {
            return JResultItem.CreateInstance("IsUpperTests")
                .Push(Char.IsUpper('0'),
                    Char.IsUpper('!'),
                    Char.IsUpper(' '),
                    Char.IsUpper('a'),
                    Char.IsUpper('z'),
                    Char.IsUpper('m'),
                    Char.IsUpper('A'),
                    Char.IsUpper('N'),
                    Char.IsUpper('Z'),
                    Char.IsUpper('ä'),  // german a - umlaut (lower case)
                    Char.IsUpper('Ä'),  // german a - umlaut (upper case)
                    Char.IsUpper("aAb", 1),
                    Char.IsUpper("aAb", 2)
            );  
        }


        static JResultItem ToLowerTests()
        {
            return JResultItem.CreateInstance("ToLowerTests")
                .Push(Char.ToLowerInvariant('0'),
                    Char.ToLowerInvariant('!'),
                    Char.ToLowerInvariant(' '),
                    Char.ToLowerInvariant('a'),
                    Char.ToLowerInvariant('z'),
                    Char.ToLowerInvariant('m'),
                    Char.ToLowerInvariant('A'),
                    Char.ToLowerInvariant('N'),
                    Char.ToLowerInvariant('Z'),
                    Char.ToLowerInvariant('ä'),  // german a - umlaut (lower case)
                    Char.ToLowerInvariant('Ä'));  // german a - umlaut (upper case)
        }

        static JResultItem ToUpperTests()
        {
            return JResultItem.CreateInstance("ToUpperTests")
                .Push(Char.ToUpperInvariant('0'),
                    Char.ToUpperInvariant('!'),
                    Char.ToUpperInvariant(' '),
                    Char.ToUpperInvariant('a'),
                    Char.ToUpperInvariant('z'),
                    Char.ToUpperInvariant('m'),
                    Char.ToUpperInvariant('A'),
                    Char.ToUpperInvariant('N'),
                    Char.ToUpperInvariant('Z'),
                    Char.ToUpperInvariant('ä'),  // german a - umlaut (lower case)
                    Char.ToUpperInvariant('Ä'));  // german a - umlaut (upper case)
        }

        static JResultItem EqualsTests()
        {
            return JResultItem.CreateInstance("EqualsTests")
                .Push(object.Equals('a', (int)'a'),
                    'a' == (int)'a',
                    object.Equals((int)'a', 'a'),
                    object.Equals('a', "a"));
        }

        static JResultItem CompareToTests()
        {
            return JResultItem.CreateInstance("CompareToTests")
                .Push(
                    'a'.CompareTo((object)'a'),
                    ((int)'a').CompareTo((object)(int)'a')
                );
        }
    }
}
